﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Library.Entities;
using MediaBrowserWS.Service.Enums;
using MediaBrowser.Library;
using System.ServiceModel;

namespace MediaBrowserWS.Service.Classes
{
    [DataContract]
    [ServiceKnownType(typeof(MetadataItem))]
    [ServiceKnownType(typeof(BasicCollectionItem))]
    public class BasicItem
    {
        public BasicItem() { }

        internal BasicItem(BaseItem item)
        {
            Id = item.Id;
            Name = item.Name;
            TypeName = item.GetType().Name;
            Type = TypeName.ToEnum<MediaTypes>();
            if (Type == MediaTypes.Unkown &&
                item is Folder)
            {
                Type = MediaTypes.Folder;
            }
            DateCreated = item.DateCreated;
        }

        [DataMember]
        public Guid Id { get; set; }

        [DataMember]
        public DateTime DateCreated { get; private set; }

        [DataMember]
        public string Name { get; set; }

        // [DataMember] // Only expose this for debugging
        public string TypeName { get; set; }

        [DataMember]
        public MediaTypes Type { get; set; }

        public override string ToString()
        {
            return Type + ": " + Name;
        }

        public static explicit operator BasicItem(BaseItem item)
        {
            return new BasicItem(item);
        }
    }
}
